package net.grapsus.arduino;

import java.io.IOException;
import java.io.File;

public class Main
{
	public static void main(String args[]) throws IOException
	{
		System.out.println("Arduino to JVM compiler v1.0");

		/* check input file */
		if(args.length != 1)
		{
			System.out.println("usage : basiccompiler source");
			return;
		}
		File file = new File(args[0]);
		if( ! file.exists())
		{
			System.out.println(args[0] + " : no such file");
			return;
		}
		
		/* generate output class name filename.b => Filename */
		int ind = file.getName().lastIndexOf('.');
		String className;
		if(ind > 0)
		{
			className = file.getName().substring(0, ind);
		}
		else
		{
			className = file.getName();
		}
		className = Character.toUpperCase(className.charAt(0)) + className.substring(1);
		System.out.println("output class : " + className);
		
		/* compile it */
	  ArduinoCompiler c = new ArduinoCompiler();
		c.parseFile(args[0]);
		c.classGen(className, className + ".class");
	}
}
